/* math module implemented functions
 * @author chenxin <chenxin619315@gmail.com>
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mathlib.h"

/* 判断一个数是否为素数 */
int cel_is_prime(int n)
{
	int j;

	/* simple check */
	if(n ==2 || n ==3)
		return 1;

	if(n == 1 || n % 2 == 0)
		return 0;

	/* loop check */
	for(j = 0; j * j < n; j++)
	{
		if(n % j == 0)
			return 0;
	}

	return 1;
}

/* get the next prime of the specified numeric */
int cel_next_prime(int n)
{
	if(n % 2 == 0)
		n++;

	for(; ! cel_is_prime(n); n = n + 2);

	return n;
}

















